package demo8;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
/*
  @Configuration
  告诉Spring这是一个配置类
  @ComponentScan
  扫描当前包下的所有类，并注册进入 bean 容器中
 */
@Configuration
@ComponentScan("demo8")
public class Config {

    @Bean
    //  创建一个 bean 容器装入返回值为 Student 的方法
    public Student initStudent(){
        return new Student();
    }

    @Bean
    public DruidDataSource  initDruidDataSource(){
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
        dataSource.setUrl("jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&allowMultiQueries=true&allowPublicKeyRetrieval=true&useSSL=false&serverTimezone=Asia/Shanghai");
        dataSource.setUsername("root");
        dataSource.setPassword("192045");
        return dataSource;
      }
}
